﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AskPro.Models.Wrappers
{
    //[Serializable]
    public class QuestionW
    {
        public Guid Id { get; set; }

        public int Type { get; set; }

        public string Body { get; set; }

        public List<OptionW> Options { get; set; } //change the option wrapper !

        public int AnswersCount { get; set; }

        public DateTime DateCreated { get; set; }

        public QuestionW()
        {

        }

        public QuestionW(DataContext.Question question)
        {
            this.Id = question.QuestionId;
            this.Type = question.Type;
            this.Body = question.Body;

            if (question.Type == 1)
            {
                this.Options = new List<OptionW>();
                this.Options.Add(new OptionW() { Flag = "A", Value = "Yes", Id = Guid.Parse("9db52b2c-89de-483a-94b7-664c31ff00f3") });
                this.Options.Add(new OptionW() { Flag = "B", Value = "No", Id = Guid.Parse("8c04d726-0998-4f13-b8b0-d99eca1b1e44") });
            }
            else
            {
                this.Options = question.QuestionsOptions.Select(qo => new OptionW(qo.Option)).ToList(); //change
            }
            
            this.AnswersCount = question.Answers.Count();
            this.DateCreated = question.DateCreated;
        }
    }
}